package top.gradual.springcloud;

import com.netflix.appinfo.InstanceInfo;
import org.springframework.cloud.netflix.eureka.server.event.*;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author: gradual
 * @Date: 2019-05-28 14:40
 */
@Component
public class EurekaStateChangeListener {


    /**
     * @description: 监听服务下线
     * @author: gradual
     * @date: 2019-03-31 21:10
     * @param: [event]
     * @return: void
     */
    @EventListener
    public void listen(EurekaInstanceCanceledEvent event) {
        System.err.println(event.getServerId() + "\t" + event.getAppName() + "服务下线！");
    }


    /**
     * @description: 监听服务的注册
     * @author: gradual
     * @date: 2019-03-31 21:10
     * @param: [event]
     * @return: void
     */
    @EventListener
    public void listen(EurekaInstanceRegisteredEvent event) {
        InstanceInfo instanceInfo = event.getInstanceInfo();
        System.err.println(instanceInfo.getAppName() + "进行注册！");
    }

    /**
     * @description: 监听服务续约
     * @author: gradual
     * @date: 2019-03-31 21:12
     * @param: [event]
     * @return: void
     */
    @EventListener
    public void listen(EurekaInstanceRenewedEvent event) {
        System.err.println(event.getServerId() + "\t" + event.getAppName() + "发送心跳，服务续约！");
    }

    /**
     * @description: Eureka服务端可用监听
     * @author: gradual
     * @date: 2019-03-31 21:12
     * @param: [event]
     * @return: void
     */
    @EventListener
    public void listen(EurekaRegistryAvailableEvent event) {
        System.err.println("Eureka服务端可用");
    }

    /**
     * @description: 监听服务端启动
     * @author: gradual
     * @date: 2019-03-31 21:13
     * @param: [event]
     * @return: void
     */
    @EventListener
    public void listen(EurekaServerStartedEvent event) {
        System.err.println("Eureka Server 启动！");
    }
}
